﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF_DtaGrid_MVVM模式
{
    public class localDb
    {
        private List<Student> StudentList;

        public localDb()
        {
            StudentList = new List<Student>();
            for (int i = 0; i < 30; i++)
            {
                StudentList.Add(new Student()
                {
                    Id = i,
                    Name = string.Format("Sample{0}", i)
                }); ;
            }
        }

        /// <summary>
        /// 获取全部的内容
        /// </summary>
        /// <returns></returns>
        public List<Student> GetStudents() => StudentList;

        public void AddStudent(Student stu)
        {
            StudentList.Add(stu);
        }

        public void DelStudent(int id)
        {
            var model = StudentList.FirstOrDefault(t => t.Id == id);
            if (model!=null)
            {
                StudentList.Remove(model);
            }
        }


        public List<Student> GetStudentsByName(string name)
            =>StudentList.Where(q => q.Name.Contains(name)).ToList();

        public Student GetStudentById(int id) => StudentList.FirstOrDefault(t => t.Id == id);

    }
}
